package com.iscas.tech.controller;

import com.iscas.tech.entity.AtScideman;
import com.iscas.tech.param.PageParam;
import com.iscas.tech.service.AtScidemanService;
import com.iscas.tech.utils.ResponseUtil;
import com.iscas.tech.vo.AtScidemanQueryVo;
import com.iscas.tech.vo.MdWithTechNeeds;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.pagination.Paging;
import io.geekidea.springbootplus.framework.shiro.util.LoginUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 科技需求表 控制器
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@RestController
@RequestMapping("/techNeeds")
@Api(value = "科技需求表API", tags = {"科技需求表"})
public class AtScidemanController extends BaseController {

    @Autowired
    private AtScidemanService atScidemanService;

    /**
     * 添加科技需求表
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加科技需求表", response = ApiResult.class)
    public ApiResult<Boolean> addAtScideman(@RequestBody MdWithTechNeeds param) throws Exception {
        if (LoginUtil.getUserId() == null) {
            return ApiResult.fail(ApiCode.UNAUTHORIZED);
        }
        param.setCreateTitle(LoginUtil.getUserId().intValue());
        return ApiResult.result(atScidemanService.saveAtScideman(param));
    }

    /**
     * 修改科技需求表
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改科技需求表", response = ApiResult.class)
    public ApiResult<Boolean> updateTechNeeds(@RequestBody MdWithTechNeeds param) throws Exception {
        return ApiResult.result(atScidemanService.updateTechNeeds(param));
    }

    /**
     * 删除科技需求表
     */
    @RequestMapping(value = "delete", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除科技需求表", response = ApiResult.class)
    public ApiResult<Boolean> deleteAtScideman(String ids) throws Exception {
        return ApiResult.result(atScidemanService.deleteTechNeeds(ids));
    }

    /**
     * 获取科技需求表详情
     */
    @RequestMapping(value = "info", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "科技需求表详情", response = AtScideman.class)
    public void getAtScideman(Long id) throws Exception {
        ResponseUtil.write(getResponse(), ApiResult.ok(atScidemanService.get(id)));
    }

    /**
     * @param pageParam 分页参数
     * @param audit     审核状态
     * @throws Exception 查询异常
     */
    @RequestMapping("/getPageList")
    @ApiOperation(value = "科技需求表分页列表", response = AtScideman.class)
    public void getTechNeedsPageList(PageParam pageParam, Integer audit) throws Exception {
        ResponseUtil.write(getResponse(), ApiResult.ok(atScidemanService.getTechNeedsPageList(pageParam, audit)));
    }

    /**
     * @param id 科技需求主键ID
     * @return 审核科技需求
     * @throws Exception 审核异常
     */
    @PostMapping("/check")
    @ApiModelProperty(value = "审核科技需求")
    public ApiResult<Boolean> checkTechNeeds(Long id) throws Exception {
        return ApiResult.result(atScidemanService.checkTechNeeds(id));
    }
}